/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Nov 15, 2013  2:47:57 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.interfaces.construction.rise.low
 * File Name : PurchaseOrderController.java
 * TODO
 */
package com.tis.interfaces.construction.rise.low;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jpa.entitys.synchro.staging.AGenDesc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import promis.utility.CommonService;
import apps.ApplConfiguration;

import com.tis.interfaces.commons.IServletCommon;
import com.tis.interfaces.commons.ServletCommon;
import com.tis.interfaces.commons.XmlResultback;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Nov 15, 2013 : 2:47:57 PM 
 * CreateBy=Chatree Siangklom
 * 
 * PurchaseOrderController
 * TODO
 */
@Controller
@RequestMapping(value=PurchaseOrderController.url)
public class PurchaseOrderController extends ServletCommon implements IServletCommon {
	
	private static final Logger logging = LoggerFactory.getLogger(PurchaseOrderController.class);
	public static final String url = "/servlet/construction/rise/low/purchase/order";

	/** (Javadoc)
	 * @see com.tis.interfaces.commons.IServletCommon#index(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * Date =Nov 15, 2013 : 2:47:57 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	@RequestMapping(method = RequestMethod.GET)
	public HttpEntity<byte[]> index(HttpServletRequest request, HttpServletResponse response) throws Exception {
		logging.info("Welcome PurchaseOrderController --->index");
		XmlResultback xmlResultback = new XmlResultback(promis.utility.ProcessModule.PURCHASE_ORDER.toString(), null, new Date());
		try{
			
			Map mapValue = super.initParam(request);

	    	AGenDesc aGenDesc = new ApplConfiguration().GetInterfaceChannel(
																			CommonService.ConvertStringToBigDecimal("1001"), 
																			CommonService.ConvertStringToBigDecimal("1002"), 
																			promis.utility.BusinessModule.CONSTRUCTION_LOW_RISE.toString(), 
																			promis.utility.ProcessModule.PURCHASE_ORDER.toString());
	    	if(CommonService.IsNullRString(aGenDesc.getValue3()).equals("Q")){
	    		new apps.promis.out.common.SyncQueueAction().PutQueue(	promis.utility.BusinessModule.CONSTRUCTION_LOW_RISE.toString(), 
																		promis.utility.ProcessModule.PURCHASE_ORDER.toString(),
																		null,
																		processAction,
																	 	mapValue);	
	    		xmlResultback.setMsgcode("QS");
	    		xmlResultback.setMsgDescription("Queue Success");
	    	}else if(CommonService.IsNullRString(aGenDesc.getValue3()).equals("D")){
	    		//Put your code Dr.Tree 2012-12-12
	    	}
			
		}catch (Exception e) {
	    	xmlResultback.setMsgcode("EE");
			xmlResultback.setMsgDescription(e.getMessage());
	    	e.printStackTrace();
	    	logging.error("Error:" + e.getMessage());
		}
		return(ToXml(xmlResultback));
	}

}
